//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package weaver.interfaces.expense.action.zcpz;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.expense.ExpenseImp;
import weaver.interfaces.expense.OAExpenseBean;
import weaver.interfaces.util.ExpenseInfoUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

public class ZCPZ_CLF_Voucher extends BaseBean implements Action {
	public ZCPZ_CLF_Voucher() {
	}

	public String execute(RequestInfo requestInfo) {
		try {
			String workflowid = requestInfo.getWorkflowid();
			String requestid = requestInfo.getRequestid();
			this.writeLog("进入ZCPZ_CLF_Voucher-----------" + requestid);
			RecordSet rs = new RecordSet();
			rs.executeSql("select formid from workflow_base where id = " + workflowid);
			rs.next();
			String formid = rs.getString("formid");
			String formtable = "formtable_main_" + formid.replaceAll("-", "");
			String ccode = "";
			double amount = 0.0D;
			String cexpenseitemcode = "";
			String citemcode = "";
			String ly = "";
			String iyear = "";
			rs.execute("select id,ks,zcxm,xm,pjje,ly,sqrq,kth1,zf,huansuan,bh from " + formtable + " where requestid="
					+ requestid);
			rs.next();
			ExpenseInfoUtil expenseInfoUtil = new ExpenseInfoUtil();
			ccode = expenseInfoUtil.getKsbm(Util.null2String(rs.getString("ks")));
			String cname = expenseInfoUtil.getCname(ccode);
			amount = Util.getDoubleValue(rs.getString("pjje").replace(",", ""), 0.0D);

			amount = Util.getDoubleValue(rs.getString("huansuan").replace(",", ""), 0.0D);
			citemcode = Util.null2String(rs.getString("xm"));
			String citemname = expenseInfoUtil.getCtn(citemcode);
			cexpenseitemcode = Util.null2String(rs.getString("zcxm"));
			String zf = Util.null2String(rs.getString("zf"));
			if ("1".equals(zf)) {
				zf = "2";
			}

			String cexpenseitemname = expenseInfoUtil.getCItemName(cexpenseitemcode);
			String kth = Util.null2String(rs.getString("kth1"));
			ly = Util.null2String(rs.getString("ly"));
			iyear = Util.null2String(rs.getString("sqrq"));
			OAExpenseBean oaExpenseBean = new OAExpenseBean();
			oaExpenseBean.setAmount(String.valueOf(amount));
			oaExpenseBean.setBilldate(iyear);
			oaExpenseBean.setBilltype("1");
			oaExpenseBean.setCcode(ccode);
			oaExpenseBean.setCname(cname);
			oaExpenseBean.setCexpenseitemcode(cexpenseitemcode);
			oaExpenseBean.setCexpenseitemname(cexpenseitemname);
			oaExpenseBean.setCitemcode(citemcode);

			// 流程编号
			String bh = Util.null2String(rs.getString("bh"));

			// 判断项目编号是否为空，如果为空就传递课题号
			if (null == citemcode || "".equals(citemcode)) {
				oaExpenseBean.setCitemcode(kth);
			}

			// 流程编号
			oaExpenseBean.setBh(bh);

			oaExpenseBean.setCitemname(citemname);
			oaExpenseBean.setLy(ly);
			oaExpenseBean.setZffs(zf);
			oaExpenseBean.setRequestid(requestid);
			ExpenseImp expenseImp = new ExpenseImp();
			expenseImp.insetExpense(oaExpenseBean);
			return "1";
		} catch (Exception var22) {
			requestInfo.getRequestManager().setMessageid("1111111111");
			requestInfo.getRequestManager().setMessagecontent(var22.getMessage());
			return "0";
		}
	}
}
